Bash - Add User script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash - Add User script
# 1  
Old 05-10-2008
Bash - Add User script

Hey folks! I'm trying to work on a script that will add a user to the system. I have the complete script, but it's not working for me, and I'm not sure what to do.

line 53: syntax error near unexpected token `0'

********************************************************

Code:
#!/bin/bash
#
#  complete add user script
#
initialize_variables ()
{
noinput=
user_id=' '
user_id_num=' '
home_directory=' '
group_id_num=' '
group_name=' '
#
#
cat /u/reedk/ulist|cut -f3 -d':'|sort -bg > luid_file
#
tuid=$(tail -1 luid_file)
let user_id_num=$tuid+1
echo "$user_id_num"
}
#
display_heading ()
{
clear
echo "           ADD USER SCREEN        "
echo " _________________________________"
}
main_menu ()
{
   let doption=100
   while [ $doption != 99 ]
    do
     display_heading


echo "  1.  Enter user real name .................. $user_name       "
echo "      Next available user ID Number ......... $user_id_num     "
echo "  2.  Enter Group ID Number ................. $group_id_num    "
echo "                Group name .....$group_name"
echo "  3.  Enter Home Directory  ................. $home_directory  "
echo "  4.  Enter Default Shell  .................. $default_shell   "
echo " "
echo " user_add -c "$user_name" -d $home_directory -g $group_id_num -G $group_name -m -s $default_shell $strt_script "
echo " "
echo "  0.  ADD USER NOW  "
echo " "
echo " "
echo "  99.  EXIT   (Take no action)  "
echo " ============================================================"
echo " Please select an option ===>   "
read option
case $option in
  0)  echo " user_add -c "$user_name" -d $home_directory -g $group_id_num -G $group_name -m -s $default_shell $strt_script "
      echo " $user_name has been added successfully"
      sleep 5
     ;;
  1)  display_heading
      echo "Please the users real name: (fi.mi.last)  ==>  "
      read confirm_reply
      if [ "$confirm_reply" = "$noinput" ]
         then
           echo " No user name entered"
         else
           user_name=$confirm_reply
           home_directory=/u/$user_name
           default_shell=/bin/bash
           if [ "$user_name" = "$( cat /u/reedk/ulist|cut -f1 -d':'|grep $user_name) " ]
             then
              echo " User name already exists"
           fi
      fi
      ;;
  2)  display_heading
      echo "Enter the primary Group ID Number ==>  "
      read confirm_reply
      group_name=' '
      if [ "$confirm_reply" = "$noinput" ]
        then
         echo "No primary group ID was entered"
        else
         grpfnd='n'
         group_id_num=$confirm_reply
         for i in $(cat /u/reedk/gfile|cut -f1,3 -d':')
          do
            if [ $(echo $i|cut -f2 -d':') -eq $group_id_num ]
             then
               grpfnd='y'
               group_name=$(echo $i|cut -f1 -d':')
            fi
            done
            if [ $grpfnd = 'n' ] || [ $group_id_num -eq 0 ]
              then
               echo "Invalid primary group number entered"
            fi
      fi
      ;;
  99)  let doption=99
       ;;
esac
done
}
#
###################################
#  BEGIN MAIN PROGRAM             #
###################################
if [ "$(whoami)" != "$( cat /u/reedk/auth.list|grep $(whoami) )" ]
   then
     echo " You are not authorized to run this script ... Contact your System Administrator "
   else
     initialize_variables
     main_menu
fi

# 2  
Old 05-10-2008
text in red is line 53
# 3  
Old 05-10-2008
Hi.

How many quotes do you count? ... cheers, drl
# 4  
Old 05-10-2008
I'm not sure what you mean. On line 53 I have 4 double quotes (")
-2 open / 2 close

The error message states:

line 53: syntax error near unexpected token `0'

But if you look at my actual code, there is no single quote next to the 0)

/Confusion

EDIT:
I should add.. I'm pretty new to scripting and UNIX in general. I have some know how of programming in C+, but a few drinks in me know.. so I may just be not seeing what you tried to tell me.

Last edited by niels.intl; 05-10-2008 at 09:30 PM..
# 5  
Old 05-10-2008
Hi.

Yes, you are correct. I did not see all the way to the end of line 53. I apologize.

One debugging tool is:
Code:
set -x

placed near the beginning of the script. It will cause every command to be listed as it is executed, letting you see what bash sees. The error will then often be apparent.

I extracted a segment of your script at the beginning of the case and it ran without error, so the problem is likely before that.

If you cannot see the error, post a small portion of the "-x" output just before and including the error message ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Curl , download file with user:pass in bash script

Hello, My question is about curl command. (ubuntu14.04) In terminal, I am able to download my mainfile with: curl -u user1:pass1 http://11.22.33.44/******* When I convert it into bash script like this: #!/bin/bash cd /root/scripts computer_ip=11.22.33.44 curl -u $1:$2... (8 Replies)
Discussion started by: baris35
8 Replies

2. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

3. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

4. Ubuntu

Exit user in bash script

I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen: sudo xhost +SI:localuser:lightdm sudo su lightdm -s /bin/bash gsettings set com.canonical.unity-greeter draw-grid false The problem is that... (3 Replies)
Discussion started by: maerlyngb
3 Replies

5. Shell Programming and Scripting

How to write bash script for creating user on multiple Linux hosts?

I wonder whether someone can help me with what I'm trying to achieve Basically, the objective is one script to create new user on more than 70 linux hosts if required. Everything works apart from the highlighted part. It gave me an output passwd: Unknown user name ''. when try to set... (35 Replies)
Discussion started by: fugeulu
35 Replies

6. Shell Programming and Scripting

Bash shell script for user creation in solaris

Hi All, I am new to shell scripting and have a task which need to be completed ASAP. I have searched all the forum and couln't find excat script which could run on solaris.can someone give me the fully working script for below. Bash shell script to create user account with paraments as... (1 Reply)
Discussion started by: sintilash
1 Replies

7. UNIX for Advanced & Expert Users

how to add new options in bash script

what i want to be is that i would like to reinvent new options that have the same functionality as ... -u is the same functionality of conv=ucase and -l have the same functionality as conv=lcase... is there a way that i can put these in my script so that whenever i will typed in command... (12 Replies)
Discussion started by: aphryllyn1
12 Replies

8. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

9. Homework & Coursework Questions

brand new user!.. Lost on BASH script writing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have just gotten into writing bash scripts for a class, part of the assignment is to read and be able to tell... (4 Replies)
Discussion started by: Byrang
4 Replies

10. Shell Programming and Scripting

Bash Script verify user input is not empty and is equal to a value

I need to create a script that has a user enter a value. I want to verify that the value is either 1,2, or 3. If it is not then I want them to try entering it again. I am using a while loop to force them to retry. I am able to test the input against 1,2, and 3, but when I test agains an... (4 Replies)
Discussion started by: spartiati
4 Replies
Login or Register to Ask a Question